#include <stdio.h>
#include <algorithm>
using namespace std;

#define TRACE(x...) 
#define PRINT(x...) TRACE(printf(x))

#define rep(i,n) for (int i=0; i<n; i++)

#define INF 0x3f3f3f3f

int n, m, c, k;
int adj[260][260];
int serv[260];
int u, v, p;
int best;

int main() {
	while (1) {
		scanf("%d %d %d %d", &n, &m, &c, &k);

		if (!n && !m && !c && !k) break;

		rep(i,n) rep(j,n) adj[i][j]=INF;

		rep(i,m) {
			scanf("%d %d %d", &u, &v, &p);

			adj[u][v]=adj[v][u]=p;
		}

		TRACE(
			rep(i,n) {
				rep(j,n) printf("%3d ", adj[i][j]==INF? -1: adj[i][j]);
				printf("\n");
			}
			printf("\n");
		)

		serv[c-1]=0;

		for (int i=c-2; i>=0; i--) 
			serv[i]=serv[i+1]+adj[i][i+1];

		TRACE(
			rep(i,c) printf("%d ", serv[i]);
			printf("\n");
		)

		for (int no=c; no<n; no++)
			rep(i,n) rep(j,n) adj[i][j]=min(adj[i][j], adj[i][no]+adj[no][j]);

		TRACE(
			rep(i,n) {
				rep(j,n) printf("%3d ", adj[i][j]==INF? -1: adj[i][j]);
				printf("\n");
			}
			printf("\n");
		)

		best = INF;
	
		for (int i=0; i<c; i++) {
			if (best>(adj[k][i]+serv[i])) best = adj[k][i]+serv[i];			
		}
	
		printf("%d\n", best);
	}	

	return 0;
}
